package com.mxpio.erp.quality.service.impl;

import com.mxpio.erp.common.quality.entity.MoInQualityOrder;
import com.mxpio.erp.common.quality.entity.MoInQualityOrderLine;
import com.mxpio.erp.common.quality.service.MoInQualityOrderService;
import com.mxpio.erp.common.workshop.entity.ManufactureOrder;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.JpaUtil;
import com.mxpioframework.system.service.impl.BaseServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service
public class MoInQualityOrderServiceImpl extends BaseServiceImpl<MoInQualityOrder> implements MoInQualityOrderService {
    @Override
    @Transactional
    public Result<List<MoInQualityOrder>> listByIds(String noticeNos) {
        if (StringUtils.isBlank(noticeNos)){
            return Result.error("查询参数为空");
        }
        String[] split = noticeNos.split(",");
        List<String> noticeNoList = Stream.of(split).collect(Collectors.toList());
        List<MoInQualityOrder> list = JpaUtil.linq(MoInQualityOrder.class)
                .collect("noticeNo", MoInQualityOrderLine.class, "noticeNo")
                .collect("bizNo", ManufactureOrder.class,"bizOrderNo")
                .in("noticeNo", noticeNoList).list();
        return Result.OK(list);
    }
}
